<?php
// redis functions
function redis_conn( $host = null , $port = null ){
    $config = $GLOBALS['config']['redis'];
	if( $host == null ) $host = $config['host'];
	if( $port == null ) $port = $config['port'];
    try{
        $redis = new Redis();
        $redis->connect($host,$port);
    }catch (Exception $e){
        echo 'can\'t connect redis';
        echo $e->getMessage();
        return false;
    }
	return $redis;
}

function get_cache( $key , $conn = NULL )
{
	if( $conn == NULL ) $conn = redis_conn();
	return   $conn->get($key);
	
}

function set_cache($key,$val='',$expire=NULL,$conn = NULL){
    if( $conn == NULL ) $conn = redis_conn();
    return $conn->set($key,$val,$expire);
}

function queue_push($key,$val,$conn=NULL){
    if( $conn == NULL ) $conn = redis_conn();
    return $conn->lPush($key,$val);
}

function queue_pop($key,$conn=NULL){
    if( $conn == NULL ) $conn = redis_conn();
    return $conn->lPop($key);
}
?>